package com.inei.formulariodedelitos2014.view;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;

import com.inei.formulariodedelitos2014.R;

public class Caratula_Activity extends Activity {

	// DOC ID
	EditText etID, etRUTA, etDPTO;

	// CAP I
	EditText etC1_1, etC1_2, etC1_3, etC1_4, etC1_5, etC1_6, etC1_7, etC1_8,
			etC1_10, etC1_10_1, etC1_10_2, etC1_10_3, etC1_10_4, etC1_10_5,
			etC1_10_6, etC1_10_7, etC1_11;
	Spinner spC1_9;

	// CAP II
	EditText etC2_1, etC2_2, etC2_3,etC2_5_2_Otro, etC2_8_Otro;
	Spinner spC2_4, spC2_5, spC2_5_2, spC2_6, spC2_7, spC2_8;
	LinearLayout llC2_5_1,llC2_5_2;

	// CAP IV
	EditText etC4_1, etC4_2_otro;
	Spinner spC4_2;

	// CAP V
	EditText etC5_1, etC5_2, etC5_3, etC5_4;

	// CAP VI
	EditText etC6_1_1, etC6_1_2, etC6_2_1, etC6_2_2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_caratula);
		iniciarComponentes();
		agregarEventos();
	}

	public void iniciarComponentes() {

		// DOC ID
		etID = (EditText) findViewById(R.id.etID);
		etRUTA = (EditText) findViewById(R.id.etRUTA);
		etDPTO = (EditText) findViewById(R.id.etDPTO);

		// CAP I
		etC1_1 = (EditText) findViewById(R.id.etC1_1);
		etC1_2 = (EditText) findViewById(R.id.etC1_2);
		etC1_3 = (EditText) findViewById(R.id.etC1_3);
		etC1_4 = (EditText) findViewById(R.id.etC1_4);
		etC1_5 = (EditText) findViewById(R.id.etC1_5);
		etC1_6 = (EditText) findViewById(R.id.etC1_6);
		etC1_7 = (EditText) findViewById(R.id.etC1_7);
		etC1_8 = (EditText) findViewById(R.id.etC1_8);
		spC1_9 = (Spinner) findViewById(R.id.spC1_9);
		etC1_10 = (EditText) findViewById(R.id.etC1_10);
		etC1_10_1 = (EditText) findViewById(R.id.etC1_10_1);
		etC1_10_2 = (EditText) findViewById(R.id.etC1_10_2);
		etC1_10_3 = (EditText) findViewById(R.id.etC1_10_3);
		etC1_10_4 = (EditText) findViewById(R.id.etC1_10_4);
		etC1_10_5 = (EditText) findViewById(R.id.etC1_10_5);
		etC1_10_6 = (EditText) findViewById(R.id.etC1_10_6);
		etC1_10_7 = (EditText) findViewById(R.id.etC1_10_7);
		etC1_11 = (EditText) findViewById(R.id.etC1_11);

		// CAP II
		etC2_1 = (EditText) findViewById(R.id.etC2_1);
		etC2_2 = (EditText) findViewById(R.id.etC2_2);
		etC2_3 = (EditText) findViewById(R.id.etC2_3);
		spC2_4 = (Spinner) findViewById(R.id.spC2_4);
		spC2_5 = (Spinner) findViewById(R.id.spC2_5);
		spC2_6 = (Spinner) findViewById(R.id.spC2_6);
		spC2_7 = (Spinner) findViewById(R.id.spC2_7);
		spC2_8 = (Spinner) findViewById(R.id.spC2_8);
		etC2_8_Otro = (EditText) findViewById(R.id.etC2_8_Otro);
		spC2_5_2 = (Spinner) findViewById(R.id.spC2_5_2);
		etC2_5_2_Otro = (EditText) findViewById(R.id.etC2_5_2_Otro);
		llC2_5_1 = (LinearLayout) findViewById(R.id.llC2_5_1);
		llC2_5_2 = (LinearLayout) findViewById(R.id.llC2_5_2);


		// CAP IV
		etC4_1 = (EditText) findViewById(R.id.etC4_1);
		etC4_2_otro = (EditText) findViewById(R.id.etC4_2_otro);
		spC4_2 = (Spinner) findViewById(R.id.spC4_2);

		// CAP V
		etC5_1 = (EditText) findViewById(R.id.etC5_1);
		etC5_2 = (EditText) findViewById(R.id.etC5_2);
		etC5_3 = (EditText) findViewById(R.id.etC5_3);
		etC5_4 = (EditText) findViewById(R.id.etC5_4);

		// CAP VI
		etC6_1_1 = (EditText) findViewById(R.id.etC6_1_1);
		etC6_1_2 = (EditText) findViewById(R.id.etC6_1_2);
		etC6_2_1 = (EditText) findViewById(R.id.etC6_2_1);
		etC6_2_2 = (EditText) findViewById(R.id.etC6_2_2);

	}

	public void agregarEventos() {

		// CAP II
		spC2_4.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				switch (pos) {
				case 1:
					// Habilito
					spC2_5.setEnabled(true);

					// Deshabilito
					spC2_8.setSelection(0);
					spC2_8.setEnabled(false);
					etC2_8_Otro.setText("");
					etC2_8_Otro.setEnabled(false);
					break;

				case 2:
					// Habilito
					spC2_8.setEnabled(true);
					etC2_8_Otro.setEnabled(true);

					// Deshabilito
					spC2_5.setSelection(0);
					spC2_5.setEnabled(false);

					break;
				default:
					// Deshabilito
					spC2_5.setSelection(0);
					spC2_5.setEnabled(false);

					// Deshabilito
					spC2_8.setSelection(0);
					spC2_8.setEnabled(false);
					etC2_8_Otro.setText("");
					etC2_8_Otro.setEnabled(false);
					break;
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});

		spC2_5.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> group, View view,
					int pos, long arg3) {
				switch (pos) {
				case 1:
					llC2_5_1.setVisibility(View.VISIBLE);
					llC2_5_2.setVisibility(View.GONE);
					spC2_5_2.setSelection(0);
					etC2_5_2_Otro.setText("");
					break;
				case 2:
					llC2_5_1.setVisibility(View.GONE);
					spC2_6.setSelection(0);
					spC2_7.setSelection(0);
					llC2_5_2.setVisibility(View.VISIBLE);
					break;
				default:
					llC2_5_1.setVisibility(View.GONE);
					spC2_6.setSelection(0);
					spC2_7.setSelection(0);
					llC2_5_2.setVisibility(View.GONE);
					spC2_5_2.setSelection(0);
					etC2_5_2_Otro.setText("");
					break;
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});
		spC2_5_2.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				switch (pos) {
				case 5:
					etC2_5_2_Otro.setVisibility(View.VISIBLE);
					
					break;
				default:
					etC2_5_2_Otro.setVisibility(View.GONE);
					etC2_5_2_Otro.setText("");
					break;
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});
		spC2_8.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> group, View view,
					int pos, long arg3) {
				switch (pos) {
				case 4:
					etC2_8_Otro.setVisibility(View.VISIBLE);
					break;
				default:
					etC2_8_Otro.setVisibility(View.GONE);
					etC2_8_Otro.setText("");
					break;
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});

		// CAP IV
		spC4_2.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				switch (pos) {
				case 9:
					etC4_2_otro.setVisibility(View.VISIBLE);
					break;

				default:
					etC4_2_otro.setVisibility(View.GONE);
					etC4_2_otro.setText("");
					break;
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
			}
		});
	}

}
